package com.dragon.repository.domain.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Contract;
import com.dragon.repository.entity.ContractArticle;
import com.dragon.repository.entity.ContractFit;
import com.dragon.repository.entity.OtherFile;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.ALWAYS)
public class ContractDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    private Integer id;

    @ApiModelProperty(value = "合同名称")
    private String name;

    @ApiModelProperty(value = "合同名称简称")
    private String simpleName;

    @ApiModelProperty(value = "甲方代表")
    private String lessor;

    @ApiModelProperty(value = "乙方名称")
    private String partyBName;

    @ApiModelProperty(value = "扫描：0否，1是")
    private Integer modeling;

    @ApiModelProperty(value = "甲方联系方式")
    private String lessorPhone;

    @TableField(exist = false)
    private String lessorArticleTitle;

    @ApiModelProperty(value = "条款")
    private String lessorArticle;

    @ApiModelProperty(value = "客户id")
    private Integer customerId;

    @ApiModelProperty(value = "负责人id（用户id）")
    private Integer adminId;

    @ApiModelProperty(value = "部门id")
    private Integer departmentId;

    @ApiModelProperty(value = "创建合同时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "合同编号")
    private String num;

    @ApiModelProperty(value = "合同金额")
    private Double money;

    @ApiModelProperty(value = "退款金额")
    private Double refundMoney;

    @ApiModelProperty(value = "状态：0 待审核 1审核通过 2审核不通过 3作废 4删除")
    private Integer status;

    @ApiModelProperty(value = "合同类型：1供销合同 2直销合同 3代理合同 4服务合同 5快销合同  ")
    private Integer type;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "签订日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date orderTime;

    @ApiModelProperty(value = "签订地点")
    private String orderAddress;

    @ApiModelProperty(value = "乙方联系电话")
    private String secondPhone;

    @ApiModelProperty(value = "附件")
    private List<OtherFile> otherFiles;

    @ApiModelProperty(value = "条款list")
    private ContractArticle articleList;

    @ApiModelProperty(value = "业务员名字")
    private String username;

    @ApiModelProperty(value = "业务员电话")
    private String userPhone;

    @ApiModelProperty(value = "部门名称")
    private String departmentName;

    @ApiModelProperty(value = "客户名称")
    private String applicantName;

    @ApiModelProperty(value = "生产负责人")
    private Integer productionPerson;

    @ApiModelProperty(value = "收款人")
    private Integer payee;

    @ApiModelProperty(value = "回款方式 (1、预付（10-100%），2、到付，3、约定时间)")
    private Integer paymentMethod;

    @ApiModelProperty(value = "预付款")
    private Double prepaymentMoney;

    @ApiModelProperty(value = "组合方式: 2:到付，3：约定时间")
    private Integer combination;

    @ApiModelProperty(value = "约定时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date agreeTime;

    @ApiModelProperty(value = "送货负责人")
    private Integer deliveryOfficer;

    @ApiModelProperty(value = "送货地址")
    private String address;

    @ApiModelProperty(value = "截至时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date endTime;

    @ApiModelProperty(value = "删除标识：0未删除，1删除")
    private Integer deleted;

    @ApiModelProperty(value = "合同进度：1待生产 2已生产 3待发货 4已发货")
    private Integer progress;


    @ApiModelProperty(value = "交货时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date deliveryTime;

    @ApiModelProperty(value = "报价信息")
    private QuotesDTO quotesData;

    @ApiModelProperty(value = "客户信息")
    private CustomerDTO customerData;

    @ApiModelProperty(value = "合同设置信息")
    private ContractFit contractFit;

    @ApiModelProperty(value = "结算方式：1现结，2月结")
    private Integer settlement;

    @ApiModelProperty(value = "补充金额")
    private Double supplementMoney;

    @ApiModelProperty(value = "补充条款")
    private String supplementArticle;


    public ContractDTO() {
    }

    public ContractDTO(Contract entity) {
        BeanUtils.copyProperties(entity, this);
    }

    public static ContractDTO convert(Contract entity) {
        return new ContractDTO(entity);
    }

    public static List<ContractDTO> convertList(List<Contract> list) {
        List<ContractDTO> resultList = new ArrayList<>();
        for (Contract entity : list) {
            resultList.add(new ContractDTO(entity));
        }
        return resultList;
    }
}
